package com.earthea.chatbot.common.config;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.ollama.OllamaStreamingChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class ChatConfig {

    @Value("${app.ollama.url}")
    private String url;

    @Value("${app.ollama.model-name}")
    private String modelName;

    @Value("${app.ollama.timeout}")
    private long timeout;

    @Bean
    public StreamingChatLanguageModel streamingChatLanguageModel() {
        return OllamaStreamingChatModel.builder().baseUrl(url).modelName(modelName).timeout(Duration.ofMinutes(timeout)).logRequests(true).logResponses(true).build();
    }

    @Bean
    public ChatLanguageModel chatLanguageModel() {
        return OllamaChatModel.builder().baseUrl(url).modelName(modelName).timeout(Duration.ofMinutes(timeout)).logRequests(true).logResponses(true).build();
    }

}
